package phone.example.com.a36kr.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.MediaController;
import android.widget.VideoView;

import phone.example.com.a36kr.R;
import phone.example.com.a36kr.bean.KrTvBean;

/**
 * Created by dllo on 16/8/30.
 */
public class KrTvLvAdapter extends BaseAdapter{
    Context mContext;
    KrTvBean krTvBean;

    public KrTvLvAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setKrTvBean(KrTvBean krTvBean) {
        this.krTvBean = krTvBean;
    }

    @Override
    public int getCount() {
        return krTvBean.getData().getData().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Video video= null;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.items_kr_tv,parent,false);
            video = new Video(convertView);
            convertView.setTag(video);
        }else {
            video = (Video) convertView.getTag();
        }
        video.videoView.setMediaController(new MediaController(mContext));
        video.videoView.setVideoURI(Uri.parse(krTvBean.getData().getData().get(position).getTv().getVideoSource()));
        video.videoView.requestFocus();

        return convertView;

    }
    public class Video{
        VideoView videoView;
        public Video(View view) {
            videoView = (VideoView) view.findViewById(R.id.kr_tv_video);
        }
    }
}